﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Linq.Expressions;

namespace Presentation.Web.MVC.Client.Extensions.HtmlHelpers
{
    public static class HtmlHelpers
    {
        public static string Truncate(this HtmlHelper helper, string input, int length)
        {
            if (input.Length <= length)
            {
                return input;
            }
            else
            {
                return input.Substring(0, length) + "...";
            }
        }

        public static string DateFormat(this HtmlHelper helper, DateTime input, string format)
        {
            return input.ToString(format);
        }

        public static string DateFormat(this HtmlHelper helper, DateTime? input, string format)
        {
            if(input.HasValue)
                return input.Value.ToString(format);
            return string.Empty;
        }

        public static string DateShortFormat(this HtmlHelper helper, DateTime input)
        {
            return input.ToShortDateString();
        }

        public static string DateShortFormat(this HtmlHelper helper, DateTime? input)
        {
            if (input.HasValue)
                return input.Value.ToShortDateString();
            return string.Empty;
        }

    }
}